<?php
// template.php
// 2005-2008 Derek "Kazan" Meek
// used by permission
class template
{
	var $tfile;
	var $vlist;
	
	function template($file_name)
	{
		$this->vlist = array();
		$this->tfile = file_get_contents($file_name);
		
		$matches = array();
		preg_match_all("/\{([\w]*)\}/i", $this->tfile, $matches);
		
		foreach ($matches[1] as $match)
		{
			$this->vlist[$match] = "";
		}
	}
	
	function assign_var($key, $value)
	{
		$this->vlist[$key] = $value;
	}
	
	function assign_vars($arr)
	{
		foreach($arr as $k=>$v)
		{
			$this->vlist[$k] = $v;
		}
	}
	
	function process()
	{
		
		$patterns = array();
		$replacements = array();
		foreach($this->vlist as $k=>$v)
		{
			
			//echo("Key: $k, Val: $v<br>");
			$patterns[] = "/\{$k\}/i";
			$replacements[] = $v;
		}
		
		return preg_replace($patterns, $replacements, $this->tfile);
	}
}
?>